<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta name="renderer" content="webkit">
		<title>原材料入库制单管理</title>
		
		<link rel="stylesheet" type="text/css" href="../../css/cm-default.css"  />
		<link rel="stylesheet" type="text/css" href="../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" />
<!-- 		<link rel="stylesheet" type="text/css" href="../../lib/ligerUI/skins/Gray2014/css/all.css" /> -->
		<link rel="stylesheet" type="text/css" href="../../lib/ligerUI/skins/ligerui-icons.css" />
		
		<link rel="stylesheet" type="text/css" href="../../lib/bootstrap//css/bootstrap.css"/>
		<link type="text/css" rel="stylesheet" href="../../css/public.css"  />
		<link type="text/css" rel="stylesheet" href="../../css/pub.css"  />
		
		<script src="../../lib/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>
		<script src="../../lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
		<script src="../../lib/autoInput/AutoInput.js" type="text/javascript"></script>
		<script src="../../js/common.js" type="text/javascript"></script>
		
		<script type="text/javascript" src="../../lib/bootstrap/js/bootstrap.js" ></script>
	    <!--解决IE实现对媒体查询（media query）的支持-->
		<!--[if lt IE 9]>
		<script type="text/javascript" src="../../lib/ie/respond.src.js"></script>
		<![endif]-->
		<script type="text/javascript" src="../../js/pub.js"></script>
		
		<script type="text/javascript">
			var GridNameCode = [
                {"Key_Nvarchar":"codeQ","Value_Nvarchar":"入库单"},
                {"Key_Nvarchar":"originQ","Value_Nvarchar":"采购申请单"}
                /*{"Key_Nvarchar":"partnerQ","Value_Nvarchar":"供应商"},
                {"Key_Nvarchar":"stateS","Value_Nvarchar":"状态"}*/
            ] ;
			$(function() {
	            InitAutoInput("gridName", GridNameCode, { key: "Key_Nvarchar", val: "Value_Nvarchar", format: "Value_Nvarchar" }, 'json');
	            var searchHeight = $(".commenGotoSite").outerHeight();
	            $(".searchContent").height(searchHeight);
        		$(".listTable").height($(window).height()-searchHeight);
	        });
	        function selectToggle(obj){
	        	if($(".searchForm").get(0).style.display=="none"){
	        		var searchHeight = $(".commenSearch").outerHeight()+$(".searchForm").outerHeight();
	        		$(".searchForm").attr("style","display:block");
	        		$(".searchContent").height(searchHeight);
	        		$(".listTable").height($(window).height()-searchHeight);
	        		$("#searchMark").removeClass("glyphicon glyphicon-menu-down");
	        		$("#searchMark").addClass("glyphicon glyphicon-menu-up");
	        	}else{
	        		var searchHeight = $(".commenSearch").outerHeight();
	        		$(".searchForm").attr("style","display:none");
	        		$(".searchContent").height(searchHeight);
	        		$(".listTable").height($(window).height()-searchHeight);
	        		$("#searchMark").removeClass("glyphicon glyphicon-menu-up");
	        		$("#searchMark").addClass("glyphicon glyphicon-menu-down");
	        	}
	        	// grid 重新加载数据
				defGrid.loadData();
	        }	
	              
		</script>
		
		
		<script type="text/javascript">
			var defGrid,paramS;
			
			//初始 查询条件对象
			paramS =new Object();
			//设置查询默认条件
// 				paramS={
// 						//默认查询状态为正常‘0’
// 						origin:'d'
// 				};
			
			$(function(){
               	defGrid = $("#query_list").ligerGrid({
                    columns:[
						{display:'id',name:'id',hide:true},
                        {display:'移库单号',name:'code',width:130,minWidth:60},
                        {display:'目的库位',name:'name',width:90,minWidth:60},
			            {display:'供应商',name:'partner_text',width:160,align:'left'},
						{display:'创建时间',name:'create_date',width:130},
			            {display:'安排日期',name:'min_date',width:80},
			            {display:'来源单据',name:'origin',width:80},
			            {display:'业务类型',name:'picking_type_id',render:sw_opt,width:80},
			            {display:'state',name:'state'},
			            {display:'单据状态',width:200,name:'state_text',align:'left'}
                    ],
                    pageSize:20,
                    usePager: true,
                    dataAction:'server',
                    url: '/stock/q',
                    contentType: "application/json; charset=utf-8",
                    postData:paramS,
                    width:'96%',
                    height:'96%',
                    checkbox:false,
                    rownumbers:false,
                    fixedCellHeight:false,
                    colDraggable:true,
                    enabledEdit:false,
                    clickToEdit:false,
                    onDblClickRow:searchRow,  //双击查询
                    onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
                    //onReload: toQuery,                   
                    param_movein:'user',
                    param_warehose:'base_point',
                    param_partner:'partner_list'
				});

				$("#pageloading").hide();
// 				ajaxSubmit("/cm/rbac/cmUser.do?method=getUserInfo", null, function(data) {
// 					$('#createUserCodeS').val(data['uid']);
// 				}, null, false);
	        	/*$("#toptoolbar").ligerToolBar(
	        			{ items: [
	        			          {text: '增加', click: new_stockp, icon:'add'},
	                              { line:true },
	                              { text: '修改',click: openModify  },
	                              { line:true },
	                              { text: '删除',}
	                             ]});*/

			});

			function sw_opt(item) {
				var swd = paramRender(item, defGrid.options.param_movein, item.move_in_user);
				if (!swd)
					swd = item.move_in_user;
				return swd;
			}
			function sw_warehose(item) {
				var swd = paramRender(item, defGrid.options.param_warehose, item.warehose_id);
				if (!swd)
					swd = item.warehose_id;
				return swd;
			}
			function sw_partner(item) {
				var swd = paramRender(item, defGrid.options.param_partner, item.partner_id);
				if (!swd)
					swd = item.partner_id;
				return swd;
			}

			//通用查询 ldz start
			function toQuery_common() {
				var key = $("#gridNameCode").val();
				var val = $("#gridName").val();
				key = key.split("Q")[0];
				//设置查询条件参数
				switch (key)
				{
					case "code":
						paramS.code = val;
					  	break;
					case "origin":
						paramS.origin = val;
					  	break;
					default:
						paramS.code = "";
						paramS.origin = "";
				}
				
				paramS.data=JSON.stringify(paramS);
				// l-list 线性结构，默认；t-tree 树型结构
				paramS.rt='l';
				
				//重置页码
				defGrid.set({
					page : 1,
					newPage : 1,
					postData : paramS
				});
				// grid 重新加载数据
				defGrid.loadData();
			}
			//通用查询 ldz end
			
			// 查询方法
			function toQuery() {
				//设置查询参数
				 
				//设置查询条件参数
				paramS.code = $("#codeQ").val();
				paramS.origin = $("#originQ").val();
				paramS.partner_id = $("#partnerQ").val();
				//状态不赋值时，按默认条件查询。
				if($("#stateS").val())
				paramS.state=$("#stateS").val();
				
				paramS.data=JSON.stringify(paramS);
				// l-list 线性结构，默认；t-tree 树型结构
				paramS.rt='l';
				
				//重置页码
				defGrid.set({
					page : 1,
					newPage : 1,
					postData : paramS
				});
				// grid 重新加载数据
				defGrid.loadData();
			}
			//新增
			function new_stockp() {
				parent.f_addTab('new_stockp','新增原材料入库单','./html/stock/stock_picking_detail.html');
			}
			//编辑
			function openModify() {
				var row = defGrid.getSelectedRow();

				if (!row) {
					$.ligerDialog.error('请先选择要编辑的原材料入库单记录。','错误');
					return;
				}
				if(row.state >= 10 )
			    {
					$.ligerDialog.error('该单据已审核或已提交，不能编辑！');
				    return;
				}
				parent.f_addTab('modify_stockp','原材料入库单维护','./html/stock/stock_picking_detail1.html?o=m&picking_id='.concat(row.id));
			}
			//编辑1 ldz
			function openModify1() {
				var row = defGrid.getSelectedRow();

				if (!row) {
					$.ligerDialog.error('请先选择要编辑的原材料入库单记录。','错误');
					return;
				}
				if(row.state >= 10 )
			    {
					$.ligerDialog.error('该单据已审核或已提交，不能编辑！');
				    return;
				}
				parent.f_addTab('modify_stockp1','原材料入库单维护','./html/stock/stock_picking_detail_pop.html?o=m&picking_id='.concat(row.id));
			}
			//明细页面 ldz
			function openMx(){
				var row = defGrid.getSelectedRow();

				if (!row) {
					$.ligerDialog.error('请先选择要查看的原材料入库单记录。','错误');
					return;
				}
				parent.f_addTab('mx_stockp','原材料入库单维护','./html/stock/stock_picking_detail_mx.html?o=m&picking_id='.concat(row.id));
			}
			//表单帮助示例 ldz
			function openHelp(){
				parent.f_addTab('help_demo','表单帮助示例','./html/stock/stock_picking_detail_help.html');
			}
			//通用单据查询 界面
// 			function searchRow(){
// 				var row = defGrid.getSelectedRow();

// 				if (!row) {
// 					$.ligerDialog.error('请先选择要查看的单据！','错误');
// 					return;
// 				}
				
// 				parent.f_addTab('new_search_stockS','单据明细信息','./html/stock/stock_picking_detail.html?o=m&picking_id='.concat(row.id));
// 			}
						//通用单据查询 界面
			function searchRow(){
				var row = defGrid.getSelectedRow();
				if (!row) {
					$.ligerDialog.error('请先选择要查看的单据！','错误');
					return;
				}
				var stockDelID=row.code;
				parent.f_addTab('new_search_stockS'+stockDelID,'单据明细信息('+stockDelID+')','./html/stock/stock_picking_detail.html?o=m&picking_id='.concat(row.id));
			}
			// 审核确认
			function toConfirm(rowid) {
				var row = defGrid.getRow(rowid);
				var param1=new Object();
			     	param1.id=row.id;
					//已审核 20
					param1.state="10";
                    param1.flow_state=row.flow_state;
                    
					upPickingDel(param1,'审核成功','审核失败');
			
		     }
			//提交质检
			function to_quality(rowid) {
				var row = defGrid.getRow(rowid);

				if(row.state < 10)
			    {					
					$.ligerDialog.error('该单据未审核，请先审核！');
				    return;
				}
				
 				$.ligerDialog.confirm('您确定要提交该项数据吗？', function(r) {
 					
		            if (!r)
			            return;
		            
					//修改 商品明细表中的 state='10'	
					var stock_move_param=new Object();
					stock_move_param.code=row.code;
					stock_move_param.state='10';
					 var stock_move_param_J = JSON.stringify(reqObj('u','stock.update.stock_move_state.update',JSON.stringify(stock_move_param)));
								
								ajaxSubmit("/cm/rbac/cm.do?m=u", stock_move_param_J, function(data1) {
									if (data1) {
										if (parseInt(data1['status']) > 0) {
											//修改单据的 state ='20'
											var param1=new Object();
											param1.id=row.id;
											// 状态被修改
											param1.state='20';
											param1.flow_state='10';
											upPickingDel(param1,'提交质检成功','提交质检失败');
										} else {
											$.ligerDialog.error('提交失败');
										}
									}
								},null,false);
 				});						
			}
// 			//提交质检
// 			function to_quality(rowid) {
// 				var row = defGrid.getRow(rowid);
				
// 				if(row.state < 10)
// 			    {					
// 					$.ligerDialog.error('该单据未审核，请先审核！');
// 				    return;
// 				}
				
//  				$.ligerDialog.confirm('您确定要提交该项数据吗？', function(r) {
 					
// 		            if (!r)
// 			            return;
// // 					//修改 商品明细表中的 state='10'	
// // 					var stock_move_param=new Object();
// // 					stock_move_param.code=row.code;
// // 					stock_move_param.state='10';
// // 					 var stock_move_param_J = JSON.stringify(reqObj('u','stock.update.stock_move_state.update',JSON.stringify(stock_move_param)));
								
// // 								ajaxSubmit("/cm/rbac/cm.do?m=u", stock_move_param_J, function(data1) {
// // 									if (data1) {
// // 										if (parseInt(data1['status']) > 0) {
// // 											//修改单据的 state ='20'
// // 											var param1=new Object();
// // 											param1.id=row.id;
// // 											// 状态被修改
// // 											param1.state='20';
// // 											param1.flow_state='10';
// // 											upPickingDel(param1,'提交质检成功','提交质检失败');
// // 										} else {
// // 											$.ligerDialog.error('提交失败');
// // 										}
// // 									}
// // 								});
// // 						//		

		            
 				
// 	        }
			
			function upPickingDel(param1,successInfo,errorInfo){
				
				 var param = JSON.stringify(reqObj('u','stock.update.picking_state.update',JSON.stringify(param1)));
					
					ajaxSubmit("/cm/rbac/cm.do?m=u", param, function(data) {
						if (data) {
							if (parseInt(data['status']) > 0) {	
								
								$.ligerDialog.success(successInfo);
								//自动刷新
								toQuery();
							} else {								
								$.ligerDialog.error(errorInfo);
							}
						}
					});
				
				
			}


			/*	
				删除处理 
			*/
			 function deleteRow() {
				 
				 var row = defGrid.getSelectedRow();
				if (!row) {
						$.ligerDialog.error('请先选择要删除的原材料入库单记录。','错误');
						return;
					}
				var rowid = row.__index;
				 if(row.state >= 10 )
					{
					 $.ligerDialog.error('该单据已审核或已提交，不能删除！');
						return;
					}
				  
		            $.ligerDialog.confirm('您确定要删除该项数据吗？', function(r) {
			            if (!r)
				            return;
		                
		                if (row['__status'] !== 'add')
		                	toDel(JSON.stringify(row));
		                defGrid.deleteRow(rowid);
		            })
		        }
			// 删除处理业务处理
			 function toDel(row) {
				
				 var param = JSON.stringify(reqObj('d','stock.delete.stock_move.prckingid',row));
					ajaxSubmit("/cm/rbac/cm.do?m=d", param, function(data) {
						if (data) {
							if (parseInt(data['status']) > 0) {
								
						     var param = JSON.stringify(reqObj('d','stock.delete.stock_picking.code',row));
						      ajaxSubmit("/cm/rbac/cm.do?m=d", param, function(data) {
								if (parseInt(data['status']) > 0) {
									toQuery();
								  $.ligerDialog.success('删除成功');
								}
								else{
										$.ligerDialog.error('删除失败');
									}
									});
							} else {
								$.ligerDialog.error('删除失败');
							}
						}
					});
			}
	    </script>
		<style type="text/css">
			label{margin: 5px 20px 5px 15px;}
			.fields{height:35px;padding-top:5px;}
			.dict-info{width: 260px;padding: 10px;}
			.diff {margin:3px 0;}
			.lineD {width:99%;float:left;position:relative;overflow:hidden;margin:10px 0 2px 2px}
			.labelD {width:13%;position:relative;float:left;padding-top:3px;}
			.dplD {width:36%;position:relative;float:left;}
			.title{font-size:14px;font-weight:bold;background-position:left;padding-left:18px;}
			.l-dialog-content-nopadding{padding:0 !important;}
		</style>
	</head>
	<body>
		<div class="list_tab contextHeight">
	    	<div class="searchContent">
	    		<div class="commenSearch">
	    			<div class="commenGotoSite">
	    				<button type="button" onclick="new_stockp();" class="btn btn-primary btn-xs">
			    			&nbsp;&nbsp;<span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;
			    		</button>
			    		<button type="button" onclick="openModify();" class="btn btn-primary btn-xs">
			    			&nbsp;&nbsp;<span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;
			    		</button>
			    		<button type="button" onclick="openModify1();" class="btn btn-primary btn-xs">
			    			&nbsp;&nbsp;<span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;
			    		</button>
			    		<button type="button" onclick="openMx();" class="btn btn-primary btn-xs">
			    			&nbsp;&nbsp;<span class="glyphicon glyphicon-eye-open"></span>&nbsp;&nbsp;
			    		</button>
			    		<button type="button" onclick="openHelp();" class="btn btn-primary btn-xs">
			    			&nbsp;&nbsp;<span class="glyphicon glyphicon-option-horizontal"></span>&nbsp;&nbsp;
			    		</button>
			    		<button type="button" onclick="deleteRow();" class="btn btn-primary btn-xs">
			    			&nbsp;&nbsp;<span class="glyphicon glyphicon-trash"></span>&nbsp;&nbsp;
			    		</button>
	    			</div>
	    			<div class="commenSearchSite">
	    				<div class="form-inline">
						  <div class="form-group contextWidth">
				    		<div class="autoBox">
				    			<span class="glyphicon glyphicon-search"></span>
		                        <!--<input type="text" class="autoInput form-control input-sm" id="country" style="width:60%;" value="" autocomplete="off" />
		                        <div class="autoList">
		                        </div>
		                        <input id="CountryCode" name="CountryCode" type="hidden" value="" />-->
		                        <span class="commenSearchTitle"></span>
		                        <input type="text" class="autoInput form-control input-sm" id="gridName" style="width:75%;" value="" autocomplete="off" />
		                        <div class="autoList">
		                        </div>
		                        <input id="gridNameCode" name="gridNameCode" type="hidden" value="" />
		                        <div style="display:inline-block;position:relative;">
		                        	<span class="zkbutton" onclick="selectToggle(this);">
			                        	<span id="searchMark" class="glyphicon glyphicon-menu-down"></span>
			                        </span>
		                        </div>
		                        &nbsp;&nbsp;
					  			<button type="button" onclick="toQuery_common();" class="btn btn-primary btn-sm">查询</button>
		                    </div>
						  </div>
						</div>
	    			</div>
	    		</div>
	    		<div class="searchForm" style="display:none;">
	    			<form id="form1" class="form-inline" action="">
					  <div class="form-group">
					    <label for="codeQ">入库单:</label>
					    <input type="text" class="form-control input-sm" id="codeQ" placeholder="">
					  </div>
					  <div class="form-group">
					    <label for="originQ">采购申请单:</label>
					    <input type="text" class="form-control input-sm" id="originQ" placeholder="">
					  </div>
					  <div class="form-group">
					    <label for="partnerQ">供应商:</label>
					  	<select name="partnerQ" id="partnerQ" param="partner_list" first="" class="form-control input-sm">
					        
				    	</select>
					  </div>
					  <div class="form-group">
					    <label for="stateS">状态:</label>
					    <select name="stateS" id="stateS" param="maInStockState" first="" class="form-control input-sm">
					        
				    	</select>
					  </div>
					  &nbsp;&nbsp;
					  <button type="button" onclick="toQuery();" class="btn btn-primary btn-sm">查询</button>
					  &nbsp;&nbsp;
					  <button type="button" onclick="toReset('#codeQ,#originQ,#partnerQ');" class="btn btn-primary btn-sm">清空</button>
					</form>
	    		</div>
	    	</div>
	    	<div class="listTable">
<!-- 	    		<div id="toptoolbar" style=""> -->
		    		
<!-- 		    	</div>  -->
				<div class="split_line"></div>
	    		<div id="query_list" style="padding: 0;margin:0 auto;"></div>
	    	</div>
	    </div>
		<input type="hidden" id="id" />
		<input type="hidden" id="state" />
		<input type="hidden" id="flow_state" />	
		<input type="hidden" id="createUserCodeS" />
		<div id="pageloading"></div>  
	</body>
</html>